/**
 * useage：
 * <pre>
 * 1. 引入js
 * import Csmonline from '@/script/csmonline.js'
 * 2.再mounted增加埋点代码
 * 如果是未登录用户： Csmonline.touch("http://127.0.0.1/fastadmin_plugin_csmmeet/public");
 * 如果是已登录用户： Csmonline.touch("http://127.0.0.1/fastadmin_plugin_csmmeet/public",1,'测试用户');   //1 为fa_user的id
 * </pre>
 */

function touch(baseurl,userid,username){
	//let baseurl = "http://127.0.0.1/fastadmin_plugin_csmmeet/public";	
	userid = (userid==null)?0:userid;
	username = (username==null)?'uniapp user':username;
	//获取当前Page地址路径
	let page = null;
	if(true){
		const pages = getCurrentPages()
		const currentPage = pages[pages.length - 1]
		page = `/${currentPage.route}`		
	}	
	//生成浏览器唯一码（H5使用cookie，小程序无法使用，只能客户端生成）
	let browserid = uni.getStorageSync("csmonline_browserid");
	if(browserid==null || browserid==''){
		browserid =  new Date().getTime();
		uni.setStorageSync("csmonline_browserid",browserid);
	}
	
	let url = baseurl+"/addons/csmonline/index/point?page=uniapp:"+page+"&username="+username+"&userid="+userid+"&browserid="+browserid;
	console.log("url="+url); 
	uni.request({
		url: url,  
		success: (sr) => {
			// setInterval(function(){
			// 	uni.request({
			// 		url: baseurl+"/addons/csmonline/index/touch?id="+sr.data.data.id+"&sign="+sr.data.data.sign+"&title=uniapp page",
			// 		success: (sr) => {}
			// 	});	
			// },sr.data.data.heartmseconds);
		}
	});			
}
export default {
	touch,
}
